<template>
  <footer class="footer">
    <span class="todo-count">剩余：<strong>{{ undone }}</strong></span>
    <ul class="filters">
      <li>
        <a @click="$emit('setSelect','all')" :class="{selected: active === 'all'}" href="javascript:;" >全部</a>
      </li>
      <li>
        <a @click="$emit('setSelect','undone')" :class="{selected: active === 'undone'}" href="javascript:;">未完成</a>
      </li>
      <li>
        <a @click="$emit('setSelect','done')" :class="{selected: active === 'done'}" href="javascript:;" >已完成</a>
      </li>
    </ul>	
    <button class="clear-completed" @click="onClear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props:['arr', 'active'],
  computed:{
    // 计算未完成的数据
    undone(){
      // 数组.filter() 有遍历的效果，返回的值是 数组
      return this.arr.filter(item=> !item.isDone).length
    }
  },
  methods:{
    // 清除已完成的数据
    onClear(){
      const undone = this.arr.filter(item => !item.isDone)
      // 触发当前组件标签上的自定义事件
      this.$emit('onClear', undone)
    }
  }
}
</script>